package com.taotao.web.controller;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.taotao.web.bean.Item;
import com.taotao.web.bean.ItemDesc;
import com.taotao.web.service.ItemService;

/**
 * 商品详情
 * @author Beck
 *
 */
@RequestMapping("item")
@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;
	
	/**
	 * 进入商品详情
	 * 同步
	 * 参数: 商品的id
	 * 返回值: ModelAndView
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	@RequestMapping("{itemId}")
	public ModelAndView toItem(@PathVariable("itemId") Long id) throws ClientProtocolException, IOException{
		ModelAndView mv = new ModelAndView();
		mv.setViewName("item");
		// 获取商品对象和商品描述对象
		Item item = itemService.getItemById(id);
		ItemDesc itemDesc = itemService.getItemDescById(id);
		mv.addObject("item", item);
		mv.addObject("itemDesc", itemDesc);
		return mv;
	}

}
